import './index.less';
import { useRef, useEffect } from 'react';
import * as echarts from 'echarts';

const EchartsBasic = () => {
  useEffect(() => {
    initChart();
  });
  const chartRef = useRef(null);
  const initChart = () => {
    const myChart = echarts.init(chartRef.current);
    const option = {
      title: {
        text: '基础柱状图',
      },
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
      },
      yAxis: {
        type: 'value',
      },
      series: [
        {
          data: [120, 200, 150, 80, 70, 110, 130],
          type: 'bar',
          itemStyle: {
            color: '#1890ff', // 自定义柱条颜色
          },
        },
      ],
    };

    // 设置配置项
    myChart.setOption(option);
  };
  return <div className="echarts-basic" ref={chartRef}></div>;
};

export default EchartsBasic;
